<?php

class FlinkController extends Controller{
	private $model;

	public function __init(){
		$this->model = K('Flink');

	}

	public function index(){
		$data = M('Flink')->all();
		$this->assign('data',$data);
		$this->display();
	}

	public function edit(){
		if(IS_POST){

		}else{
			$data = M('Flink')->where(array('fid'=>Q('fid')))->find();
			$this->assign('data',$data);
			$this->display();
		}
	}

	public function add(){

		if(IS_POST){
			p($_POST);die;
			if($this->model->addData()){
				$this->success('添加成功');
			}else{
				$this->error('添加失败');
			}
		}else{
			$this->display();
		}
	}

	public function upload()
    {
        $upload = new Upload('Upload/Flink/' . date('y/m'));
        $file = $upload->upload();
        if (empty($file)) {
            $this->ajax('上传失败');
        } else {
            $data = $file[0];
            $this->ajax($data);
        }
    }

    public function delPic(){
    	$path = Q('path');
    	$re = is_file($path) and unlink($path);
    	if($re){
    		// $this->ajax(array('status'=>1));
    		$data = array(
    			'status'=>1,
    		);
    		echo json_encode($data);die;
    	}
    }
}